# 2.已知列表list1 = [11,22,11,33,44,55,66,55,66],统计列表中每个元素出现的次数，生成一个字典，结果为{11:2,22:1…}
list1 = [11,22,11,33,44,55,66,55,66]
dict1 = {num:list1.count(num) for num in list1}
print(dict1)

# 3.已知如下列表students，在列表中保存了6个学生的信息，根据要求完成下面的题目
print("=" * 50)

students = [
{'name': '小花', 'age': 19, 'score': 90, 'gender': '女', 'tel':
'15300022839'},
{'name': '明明', 'age': 20, 'score': 40, 'gender': '男', 'tel':
'15300022838'},
{'name': '华仔', 'age': 18, 'score': 90, 'gender': '女', 'tel':
'15300022839'},
{'name': '静静', 'age': 16, 'score': 90, 'gender': '不明', 'tel':
'15300022428'},
{'name': 'Tom', 'age': 17, 'score': 59, 'gender': '不明', 'tel':
'15300022839'},
{'name': 'Bob', 'age': 18, 'score': 90, 'gender': '男', 'tel':
'15300022839'}
]
# a.统计不及格学生的个数
fail_count = [ sc['score'] for sc in students if sc['score'] < 60]
print(fail_count)
print(len(fail_count))
print("=" * 50)
# b.打印不及格学生的名字和对应的成绩
fail_list = [sc for sc in students if sc['score'] < 60]
print("不及格学生名单:")
for student in fail_list:
    print(f"姓名: {student['name']}, 成绩: {student['score']}")

# c.统计未成年学生的个数
small_age_count = [ sc['age'] for sc in students if sc['age'] < 18]
print(small_age_count)
print(len(small_age_count))
print("=" * 50)
# d.打印手机尾号是8的学生的名字
last_8_count = [ sc['name'] for sc in students if int(sc['tel']) % 10 == 8]
print(last_8_count)
print(len(last_8_count))
print("=" * 50)
# e.打印最高分和对应的学生的名字
max_score = max([sc['score'] for sc in students])
max_score_student = [sc['name'] for sc in students if sc['score'] == max_score ]
print(max_score_student)
print("=" * 50)
# f.删除性别不明的所有学生
new_students = [stu_dict for stu_dict in students if stu_dict['gender'] != "不明"]
print(new_students)


# 5.dict_list = [{'科目':'政治', '成绩':98}, {'科目':'语文', '成绩':77}, {'科目':'数学', '成绩':99}, {'科目':'历史', '成绩':65}]，去除列表中成绩小于70的字典 【列表推导式完成】
dict_list = [{'科目':'政治', '成绩':98}, {'科目':'语文', '成绩':77}, {'科目':'数学', '成绩':99}, {'科目':'历史', '成绩':65}]
new_dict_list = [stu_dict for stu_dict in dict_list if stu_dict['成绩'] >= 70]
print(new_dict_list)